home *** CD-ROM | disk | FTP | other *** search
- Path: fido.asd.sgi.com!austern
- From: "john (j.d.) hickin" <hickin@bnr.ca>
- Newsgroups: comp.std.c++
- Subject: (no subject)
- Date: 30 Jan 1996 09:51:25 PST
- Organization: Bell-Northern Research
- Approved: austern@isolde.mti.sgi.com
- Message-ID: <4elfbq$21r@bmtlh10.bnr.ca>
- NNTP-Posting-Host: isolde.mti.sgi.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Original-Date: Tue, 30 Jan 1996 16:00:58 +0000
- Content-Identifier: (no subject)
- X-Mailer: Mozilla 1.1 (X11; I; HP-UX A.09.05 9000/715)
- X-Url: news:comp.std.c++
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBVAwUBMQ5asUy4NqrwXLNJAQH0dQIAixE2FwNm9WPIaZ7cVyXjYzumYDMs42Dq
- ockk8f5kvJQCrFNXX1+fvwyyTjUnkVQjSMjWniSMaY6XnzLf8k992w==
- =EZwq
- Originator: austern@isolde.mti.sgi.com
-
- Some current compilers allocate memory for heap objects from inside
- the constructor code. This isn't great when exceptions can be thrown
- and indeed generated code from compilers that support exception handling
- seems to abandon the idea.
-
- Does the standard say anything about how memory should be allocated?
- My question is motivated by the following simple program which exhibits
- different behavior when exception handling is enabled compared to when
- it isn't. Would such behavior be accptable inder the provisions of the
- standard?
-
- // -----------------------------------------------------------------
-
- #include <stddef.h>
-
- struct Y
- {
- Y() {}
- void* allocate() { return 0; }
- };
-
- struct X
- {
- X() {}
- void* operator new( size_t ) { return (void*)42; }
- void* operator new( size_t , Y& alloc ) { return alloc.allocate(); }
- void operator delete( void* ) {}
- //void operator delete( size_t , Y& ); // not yet supported by my compiler
- };
-
-
- #include <iostream.h>
-
- main()
- {
- Y y;
- X* ptr = new(y) X;
- cout << "ptr == " << (int)ptr << "\n";
- }
-
- The output is 0 when exception handling is enabled and 42 when it isn't.
-
-
- --
- John Hickin Bell-Northern Research, Montreal, Quebec
- (514) 765-7924 hickin@bnr.ca
- ---
- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
- Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
- is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
-